<div class="container">			
	<h2 class="page-header">修改信息</h2>
	
	<form id="form1" class="form-horizontal">				
		<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">昵称</label>
			<div class="col-sm-8">
				<input type="text" id="userName" name="userName" class="form-control"/>
			</div>
		</div>	
		<!--<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">账号</label>
			<div class="col-sm-8">
				<input type="text" id="userLoginName" name="userLoginName" class="form-control" readonly/>
			</div>
		</div>-->
		<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">邮箱</label>
			<div class="col-sm-8">
				<input type="text" id="userEmail" name="userEmail" placeholder="请输入邮箱地址" class="form-control"/>
			</div>
		</div>	
		<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">电话</label>
			<div class="col-sm-8">
				<input type="text" id="userPhone" name="userPhone" placeholder="请输入电话号码" class="form-control"/>
			</div>
		</div>
		<!--<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">网龄</label>
			<div class="col-sm-8">
				<input readonly type="text" id="userHiredate" name="userHiredate" 
					class="form-control" readonly/>
			</div>
		</div>-->
		<!--<div class="form-group">
			<label for="" class="col-sm-2">工资</label>
			<div class="col-sm-8">
				<input type="text" id="empSalary" name="empSalary" placeholder="请输入工资" class="form-control"/>
			</div>
		</div>	-->
		<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">专业</label>
			<div class="col-sm-8">
				<select name="majors.majorsId" id="majorsId" class="form-control">
					<option value="">请选择专业</option>													
				</select>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">职务</label>
			<div class="col-sm-8">
				<select name="job.jobId" id="jobId" class="form-control">
					<option value="">请选择职务</option>													
				</select>
			</div>
		</div>	
		<div class="form-group">
			<label for="" class="col-sm-2" style="color: white;">简介</label>
			<div class="col-sm-8">
				<textarea id="userIntro" name="userIntro" class="form-control"></textarea>
			</div>
		</div>				
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-8">
				<input type="hidden" id="userId" name="userId" />
				<!--<input type="hidden" id="userLoginName" name="userLoginName" class="form-control" readonly/>-->
				<input type="button" value="修改" class="btn btn-success" id="updateBtn"/>
				<!--<input type="button" value="取消" class="btn btn-warning" onclick="window.parent.layer.closeAll()" />-->
			</div>					
		</div>
	</form>			
</div>		

<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript" src="js/global.js" ></script>
<script type="text/javascript" src="js/bootstrap/js/bootstrap.js" ></script>
<script type="text/javascript" src="js/layer/layer.js" ></script>
<script type="text/javascript" src="js/datetimepicker/jquery.datetimepicker.js" ></script>
<script type="text/javascript" src="js/param.js" ></script>
<script>

//	var params = {
//		userName: $('#userName').val(),
//		userPhone: $('#userPhone').val(),
//		userEmail: $('#userEmail').val(),
//		majorsId: $('#majorsId').val(),
//		jobId: $('#jobId').val(),
//		userIntro: $('#userIntro').val(),
//		userId: $('#userId').val()
//	}

	//统一设置ajax同步
	$.ajaxSetup({
		async:false
	});
	//动态生成部门列表框
	$.ajax({
		url:baseUrl + '/majors/query',
		type:'GET',
		dataType:'json'				
	})
	.done(function(data){				
		$.each(data, function(index,item) {					
			var opt = '<option value="' + item.majorsId + '">' + item.majorsName + '</option>';
			$('#majorsId').append(opt);
		});					
	})
	.fail(function(xhr,status,text){
		layer.msg('专业列表请求失败');				
	});		
	
	//动态生成职务列表框
	$.ajax({
		url:baseUrl + '/job/query',
		type:'GET',
		dataType:'json'				
	})
	.done(function(data){				
		$.each(data, function(index,item) {					
			var opt = '<option value="' + item.jobId + '">' + item.jobName + '</option>';
			$('#jobId').append(opt);
		});					
	})
	.fail(function(xhr,status,text){
		layer.msg('职务列表请求失败');				
	});	
	
	//获得员工信息
//	var userId = getParam('userId');
	
	//获得员工数据的数据模型中数组下标
//	var index = getParam('index');
	
//	var userLoginName = localStorage.getItem('userLoginName');
				
	$.getJSON(baseUrl + '/user/message',function(data){
		$('#userName').val(data.userName);
		$('#userLoginName').val(data.userLoginName);
		$('#userEmail').val(data.userEmail);
		$('#userPhone').val(data.userPhone);
		$('#userHiredate').val(data.userHiredate);
		$('#majorsId').val(data.job.majors.majorsId);
		$('#jobId').val(data.job.jobId);
		$('#userId').val(data.userId);
		$('#userIntro').val(data.userIntro);
		
		
	})
	.error(function(){
		layer.msg('网络请求失败');
	});
	//表单验证函数
	function checkForm() {
		//邮箱验证
		//电话号码验证
		//工资验证（工资必须是职务范围之内的工资）
		//部门
		var majorsId = $('#majorsId');
		
		if (majorsId.val() == '') {
			layer.msg('请选择一个专业');
			majorsId.focus();
			return false;
		}
		
		//职务
		var jobId = $('#jobId');
		
		if (jobId.val() == '') {
			layer.msg('请选择一个职务');
			jobId.focus();
			return false;
		}
		
		//员工简介（最多600字）
						
						
		return true;
	}
	
	
	//增加按钮单击事件
	$('#updateBtn').click(function(){
		
		//调用表单验证
		if ( !checkForm() )
			return;
			
		//ajax请求
		var params = $('#form1').serialize();
//		alert(params);
		
		$.post(baseUrl + '/user/update',params,function(data){
			layer.msg('修改成功');
			
			//修改前端员工数据
//			var user = window.parent.vue.userData[index];
//			
//			user.userId = userId;
//			user.userName = $('#userName').val();
//			user.userEmail = $('#userEmail').val();
//			user.userPhone = $('#userPhone').val();
//			user.majors.majorsName = $('#majorsId option:selected').text();
//			user.job.jobName = $('#jobId option:selected').text();
//			user.userIntro = $('#userIntro').text();
								
			setTimeout(function(){												
				window.parent.layer.closeAll();
			},500);
		})
		.error(function(){
			layer.msg('修改请求失败');					
		});				
		
	});			
							
</script>		
